{extend name="layout/common_layout" /}
{block name="body"}
<!--tab标签-->
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">编辑文章</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form id="uploadForm" enctype="multipart/form-data">
                文件:<input type="file" name="files" multiple="multiple" /><br>
                用户ID：<input type="text" name="uid" value=""/>   <!--用户的ID-->
               文件ID： <input type="text" name="fileId" value="" readonly>  <!--项目上传文件的ID--->
            </form>
            <button id="upload" >上传文件</button>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<!--<script src="__JS__/kindeditor/kindeditor.config.js"></script>-->
<!--<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>-->
<script src="__JS__/ueditor/ueditor.config.js"></script>
<script src="__JS__/ueditor/ueditor.all.min.js"></script>
{/block}
{block name="script"}
<script>

    $("#upload").click(function () {
        var formData = new FormData($('#uploadForm')[0]);
        var uid = $("[name = 'uid']").val();
        if (!uid) {
            alert('您还未登陆，请先登陆');
            return;
        }
        formData.append("uid", uid);
        $.ajax({
            type: 'post',
            url: "{:url('project/uploadfiles')}",
            data: formData,
            dataType:'json',
            cache: false,
            processData: false,
            contentType: false,
            success:function(data){
                if (data['code'] == 0) {
                    alert(data['msg']);
                } else {
                    var fileId = $("[name = 'fileId']").val();
                    if (fileId) {
                        $("[name = 'fileId']").val(fileId+','+data['fid']);
                    } else {
                        $("[name = 'fileId']").val(data['fid']);
                    }
                    alert(data['msg']);
                    alert($("[name = 'fileId']").val());
                }
            },
            error:function(error){
                alert("上传失败");
            }
        })
    });


</script>
{/block}